
using Geek.Server.App.Common;
using Geek.Server.Core.Net;

namespace Server.Logic.Common.Handler;

public static class NetChannelExtensions
{
    public static void SetResponse(this NetChannel channel, uint rpcId, ResponseMessage response)
    {
        response.RpcId = rpcId;
        channel.Write(response);
    }
    
    public static void SetResponse(this NetChannel channel, uint rpcId, MessageErrorCode code)
    {
        channel.Write(new CommonResp
        {
            RpcId = rpcId,
            ErrorCode = (int)code
        });
    }

    public static void Notify(this NetChannel channel, Message message)
    {
        if (message == null)
            return;
        
        channel.Write(message);
    }
}